import {
  combineReducers, /*  ReducersMapObject, AnyAction  */,
} from "redux";
import counter, { CounterState } from "./counter";
import router, { RouterState } from "./router";
//合并后的状态树长 {counter:{number:0}}
export interface CombinedState {
  counter: CounterState;
  router:RouterState
}
export type Reducer<S = any, A extends Action = AnyAction> = (
  state: S | undefined,
  action: A
) => S;
export interface AnyAction extends Action {
  // Allows any extra properties to be defined in an action.
  [extraProps: string]: any;
}
//动作对象必须至少有一个属性是type,它的类型是默认是any
export interface Action<T = any> {
  type: T;
}
/**
 * ReducersMapObject其实一个对象类型
 * S 合并后的状态树
 * A 动作可以派发给仓库,或者说reducer的动作
 */
export type ReducersMapObject<S = any, A extends Action = Action> = {
  //keysof  S获取合并后状态的所有属性的集合
  //K in 某个属性
  //S[K] CombinedState['counter'] CounterState A AnyAction
  [K in keyof S]: Reducer<S[K], A>;
};
type k = keyof CombinedState; // counter|router
let reducers: ReducersMapObject<CombinedState, AnyAction> = {
  counter,
  router
};
let reducer: Reducer<CombinedState> = combineReducers<CombinedState>(reducers);

export default reducer;

/* S = CombinedState;
keyof S = counter|router 


for (let K in counter|router){
   Reducer<CombinedState[counter],AnyAction>
   Reducer<CombinedState[router],AnyAction>
} */